package com.aliyun.messagemgt.util;


import com.alibaba.cloudapi.sdk.core.BaseApiClient;
import com.alibaba.cloudapi.sdk.core.BaseApiClientBuilder;
import com.alibaba.cloudapi.sdk.core.enums.Method;
import com.alibaba.cloudapi.sdk.core.enums.ParamPosition;
import com.alibaba.cloudapi.sdk.core.enums.Scheme;
import com.alibaba.cloudapi.sdk.core.model.ApiRequest;
import com.alibaba.cloudapi.sdk.core.model.ApiResponse;
import com.alibaba.cloudapi.sdk.core.model.BuilderParams;
import org.apache.http.annotation.NotThreadSafe;
import org.apache.http.annotation.ThreadSafe;

import java.util.Map;

/**
 * @author
 * @date
 */
@ThreadSafe
public class SyncApiListClient extends BaseApiClient {

    private SyncApiListClient(BuilderParams builderParams) {

        super(builderParams);
    }

    @NotThreadSafe
    public static class Builder extends BaseApiClientBuilder<Builder, SyncApiListClient> {

        @Override
        protected SyncApiListClient build(BuilderParams params) {
            // params.setExtParam("apache.httpclient.builder", new CommonLogHttpClientBuilder());
            return new SyncApiListClient(params);
        }
    }

    public static Builder newBuilder() {

        return new Builder();
    }

    public static SyncApiListClient getInstance() {

        return getApiClassInstance(SyncApiListClient.class);
    }

    public ApiResponse apiList(Map<String, String> queryParams, Map<String, String> headerParams, Map<String, String> formParams, String apiPath, String groupHost) {

        ApiRequest apiRequest = new ApiRequest(Scheme.HTTP, Method.POST_FORM, groupHost, apiPath);
        apiRequest.addMappedParams(queryParams, ParamPosition.QUERY);
        apiRequest.addMappedParams(headerParams, ParamPosition.HEADER);
        apiRequest.addMappedParams(formParams, ParamPosition.FORM);

        return syncInvoke(apiRequest);
    }


    public ApiResponse apiList(Map<String, String> queryParams, Map<String, String> headerParams, String apiPath, String groupHost, byte[] body) {

        ApiRequest apiRequest = new ApiRequest(Scheme.HTTP, Method.POST_BODY, groupHost, apiPath, body);
        apiRequest.addMappedParams(queryParams, ParamPosition.QUERY);
        apiRequest.addMappedParams(headerParams, ParamPosition.HEADER);

        return syncInvoke(apiRequest);
    }

}
